package util.qualitycontainers.qualities.generics;

import java.awt.Dimension;
import util.qualitycontainers.MorphException;
import util.qualitycontainers.qualities.IComponent;


@SuppressWarnings("serial")
public class DimensionQ extends Dimension implements IComponent
{

    @Override
    public int compareTo (IComponent o)
    {
        if (this.isSameQualityClass(o)) return ((Integer) (height * width)).compareTo((((DimensionQ) o).height * ((DimensionQ) o).width));
        throw new MorphException(MorphException.DIFFERENT_QUALITIES);
    }


    @Override
    public void setTo (IComponent q)
    {
        this.setSize((DimensionQ) q);
    }


    @Override
    public boolean isSameQualityClass (IComponent other)
    {
        return isSameQualityClass(other.getClass());
    }


    @Override
    public boolean isSameQualityClass (Class<? extends IComponent> cls)
    {
        return cls.equals(DimensionQ.class);
    }


    @Override
    public boolean equals (IComponent q)
    {
        return (height == ((DimensionQ) q).height) &&
               (width == ((DimensionQ) q).width);
    }

}
